<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../node_modules/vue/dist/vue.js"></script>

    <div id="app">
        <button @click="count++">被点击了 {{count}} 次</button>
        <counter></counter>

        <button-counter></button-counter>
    </div>

    <script>
        // 全局声明注册组件
        Vue.component("counter", {
            template: `<button @click="count++">被点击了 {{count}} 次</button>`,
            data() {
                return {
                    count: 0
                }
            },
        })

        // 局部声明组件
        const buttonTemplate = {
            template: `<button @click="count++">被点击了 {{count}} 次</button>`,
            data() {
                return {
                    count: 0
                }
            }
        }

        new Vue({
            el: '#app',
            data: {
                count: 0
            },
            components:{
                'button-counter':buttonTemplate
            }
        })
    </script>
</body>

</html>